<extend name="Public/base"/>

<block name="body">
    <script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
    <div class="main-title">
        <!--<h2>{$info['id']?'编辑':'新增'}轮播图</h2>-->
        <h2>修改分类</h2>
    </div>
    <form action="{:U('Goodstype/upd')}" method="post" class="form-horizontal">
        <div class="form-item">
            <label class="item-label">分类名称</label>
            <div class="controls">
                <input type="text" class="text input-large" name="name" value="{$info.name}">
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">上级分类<span class="check-tips">（支持无限级）</span></label>
            <div class="controls">
                <select name="pid">
                    <option value="0">顶级分类</option>
                    <volist name="Menus" id="menu">
                        <option value="{$menu.id}">{$menu.title_show}{$menu.name}</option>
                    </volist>
                </select>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">排序<span class="check-tips">（用于分组显示的顺序）</span></label>
            <div class="controls">
                <input type="text" class="text input-small" name="rank" value="{$info.rank|default=0}">
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">隐藏<span class="check-tips"></span></label>
            <div class="controls">
                <label class="radio"><input type="radio" name="state" value="0">是</label>
                <label class="radio"><input type="radio" name="state" value="1">否</label>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">分类描述</label>
            <div class="controls">
                <input type="text" class="text input-large" name="remark" value="{$info.remark}">
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">图片上传<span class="check-tips">(注意同名覆盖)</span></label>
            <div class="controls">
                <div class="controls">
                    <!--图片上传-->

                    <input type="file" id="upload_picture_{$field.name}">
                    <input type="hidden" name="picname" id="cover_id_{$field.name}" value="{$data[$field['name']]}"/>
                    <!--显示图片-->
                    <div class="upload-img-box">
                        <input type="hidden" name="picture"  value="{$info.picture}"/>
                        <div class="upload-pre-item"><img src="{$info.picture}"/></div>
                        <notempty name="data[$field['name']]">
                            <div class="upload-pre-item">
                                <img src="{$data[$field['name']]|get_cover='path'}"/></div>
                        </notempty>
                    </div>
                </div>
                <script type="text/javascript">
                    //上传图片
                    /* 初始化上传插件 */
                    $("#upload_picture_{$field.name}").uploadify({
                        "height"          : 30,
                        "swf"             : "__STATIC__/uploadify/uploadify.swf",
                        "fileObjName"     : "download",
                        "buttonText"      : "上传图片",
                        "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id(),'setpath'=>'GOODS_PICTURE_UPLOAD'))}",
                        "width"           : 120,
                        'removeTimeout'	  : 1,
                        'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
                        "onUploadSuccess" : uploadPicture{$field.name}
                    });
                    function uploadPicture{$field.name}(file, data){
                        var data = $.parseJSON(data);
                        var src = '';
                        if(data.status){
                            $("#cover_id_{$field.name}").val(data.id);
                            src = data.url || '__ROOT__' + data.path
                            $("#cover_id_{$field.name}").parent().find('.upload-img-box').html(
                                    '<input type="hidden" name="picture"  value="__ROOT__'+data.path+'"/><div class="upload-pre-item"><img src="' + src + '"/></div>'
                            );
                        } else {
                            updateAlert(data.info);
                            setTimeout(function(){
                                $('#top-alert').find('button').click();
                                $(that).removeClass('disabled').prop('disabled',false);
                            },1500);
                        }
//                        console.log();
                    }

                </script>
            </div>
        </div>
        <div class="form-item">
            <input type="hidden"  name="id" value="{$info.id}">

            <button class="btn submit-btn" id="submit" type="submit" target-form="form-horizontal">确 定</button>
            <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
        </div>
    </form>
</block>

<block name="script">
    <script type="text/javascript">
        Think.setValue("pid", {$info.pid|default = 0});
        Think.setValue("state", {$info.state|default = 1});
        //导航高亮
        $('.side-sub-menu').find('a[href="{:U('index')}"]').closest('li').addClass('current');
    </script>
</block>
